<?php
session_start();
include_once dirname(__FILE__).'/../../db/rdb/factory/RDBDAOFactory.php';
if(isset($_SESSION['user']) && isset($_POST['projectname'])) {
	$user = unserialize($_SESSION['user']);
	$rdbFactory = DAOFactory::getDAOFactory(DAOFactory::$RDB);
	$userJoinProjectDAO = $rdbFactory->getUserJoinProjectDAO();
	$projectDAO = $rdbFactory->getProjectDAO();
	
	$maxProjectPK = $projectDAO->getMaxPK();
	
	$project = new Project($maxProjectPK+1, $_POST['projectname'], date('Y-m-d H:i:s', time()));
	$userJoinProject = new UserJoinProject($maxProjectPK+1, $user->getUserPK(), UserJoinProject::$OWNER_ROLE);
	
	$i = $projectDAO->insert($project);
	$j = $userJoinProjectDAO->insert($userJoinProject);
	
	if($i > 0 && $j > 0) {
		echo json_encode(array('success' => true));
	} else {
		echo json_encode(array('success' => false));
	}
}
?>